//
//  BookAccountCell.swift
//  LiteAccount
//
//  Created by 刘伟 on 2017/5/10.
//  Copyright © 2017年 刘伟. All rights reserved.
//

import UIKit

enum AccountCellType {
    case add
    case edit
}

class BookAccountCell: UICollectionViewCell {
    
    var type: AccountCellType = .edit {
        didSet {
            switch type {
            case .add:
                titleLabel.isHidden = true
                amountLabel.isHidden = true
                initAddView()
            case .edit:
                addImageView.isHidden = true
                initNormalView()
            }
        }
    }
    
    var data: AccountDetailModel? {
        didSet {
            if let currentData = data {
                titleLabel.text = currentData.name
                amountLabel.text = String(format: "%.2f", currentData.amount)
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentView.addSubview(titleLabel)
        self.contentView.addSubview(amountLabel)
        self.contentView.addSubview(addImageView)
    }
    
    func initNormalView() {
        self.contentView.backgroundColor = UIColor.primary
        self.contentView.layer.cornerRadius = 5
        titleLabel.isHidden = false
        amountLabel.isHidden = false
        titleLabel.snp.makeConstraints { (make) in
            make.top.left.equalTo(5)
        }
        amountLabel.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
        }
    }
    
    func initAddView() {
        self.contentView.backgroundColor = UIColor.la_bg
        self.contentView.layer.cornerRadius = 5
        addImageView.isHidden = false
        addImageView.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalTo(addImageView.snp.height)
            make.width.equalTo(50)
        }
    }
    
    fileprivate lazy var addImageView: UIImageView = {
        let object = UIImageView()
        object.contentMode = .scaleToFill
        object.image = UIImage(named: "icon_addition_fill.png")
        return object
    }()
    
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: 视图组建
    fileprivate lazy var titleLabel: UILabel = {
        let object = UILabel()
        object.textAlignment = .left
        object.textColor = UIColor.white
        object.font = UIFont.la_Font(ofSize: 12)
        object.text = "支付宝"
        return object
    }()
    
    fileprivate lazy var amountLabel: UILabel = {
        let object = UILabel()
        object.textAlignment = .left
        object.textColor = UIColor.white
        object.font = UIFont.la_Font(ofSize: 30)
        object.text = "10000.00"
        return object
    }()

}
